package com.fjw.service.impl;

import com.fjw.mapper.ArticleMapper;
import com.fjw.pojo.Article;
import com.fjw.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public void add(Article article) {
        articleMapper.add(article);
    }

    @Override
    public Article findById(Integer id) {
        return articleMapper.findById(id);
    }

    @Override
    public List<Article> findByCategory(String job_category,String major_category){
        if(!Objects.equals(job_category, "") && !Objects.equals(major_category, "")){
            return articleMapper.findByCategory(job_category, major_category);
        }else if (Objects.equals(job_category, "") && !Objects.equals(major_category, "")){
            return articleMapper.findByMajorCategory(major_category);
        }else if (!Objects.equals(job_category, "") && Objects.equals(major_category, "")){
            return articleMapper.findByJobCategory(job_category);
        }else if (Objects.equals(job_category, "") && Objects.equals(major_category, "")){
            return articleMapper.getAll();
        }
        return null;
    }

    @Override
    public List<Article> findByAuthor(Integer author) {
        return articleMapper.findByAuthor(author);
    }

    @Override
    public void deleteById(Integer id) {
        articleMapper.deleteById(id);
    }

    @Override
    public void updateById(Article article) {
        articleMapper.updateById(article);
    }

    @Override
    public List<Article> getAll(){
        return articleMapper.getAll();
    }
}
